﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Swan.SwanWakeUp.Controls
{
    /// <summary>
    /// Interaction logic for AlarmSetter.xaml
    /// </summary>
    public partial class AlarmSetter : UserControl
    {
        public event Action<DateTime> AlarmUpdated;
        public AlarmSetter()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(AlarmSetter_Loaded);
            //this.alarm = (SetAlarm)this.DataContext;
        }

        void AlarmSetter_Loaded(object sender, RoutedEventArgs e)
        {
            //if (this.alarm.AlarmEnabled)
            //{
            //    if(this.alarm.AlarmDateTime > DateTime.Now && this.alarm.AlarmDateTime < DateTime.Now.AddDays(1) && this.alarm.AlarmEnabled)
            //    {
            //        this.udHour.Value = this.alarm.AlarmDateTime.Hour;
            //        this.udMinute.Value = this.alarm.AlarmDateTime.Minute;
            //        if (this.AlarmUpdated != null)
            //        {
            //            this.AlarmUpdated(this.alarm.AlarmDateTime);
            //        }
            //    }
            //}
        }

        //public SetAlarm Alarm
        //{
        //    get { return this.alarm; }
        //}

        //private DateTime GetAlarm()
        //{
        //    bool isNextDay = DateTime.Now.Hour > this.udHour.Value;
        //    DateTime a = DateTime.Now;
        //    if (isNextDay)
        //        a = a.AddDays(1);

        //    return (new DateTime(a.Year, a.Month, a.Day, (int)this.udHour.Value, (int)this.udMinute.Value, 0));
        //}

        //internal void SetTheAlarm(string user, string password)
        //{
        //    bool ok = this.alarm.SetTheAlarm(user, password, this.GetAlarm(), this.GetAlarm().AddHours(2));
        //    if (ok)
        //    {
        //        MessageBox.Show("The alarm has been set");
        //    }
        //    else
        //    {
        //        MessageBox.Show(this.alarm.ErrorMsg, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
        //    }
        //}

        //private void NumericUpDown_ValueChanged(object sender, RoutedEventArgs e)
        //{
        //    if (this.AlarmUpdated != null)
        //    {
        //        this.AlarmUpdated(this.GetAlarm());
        //    }
        //}
    }
}
